package com.prepowers.cake.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.prepowers.cake.data.vo.UserForm;
import com.prepowers.cake.service.UserService;

import groovy.util.logging.Slf4j;

@Controller
@Slf4j
public class LoginViewController {
	
	@Autowired	
	private UserService uService;
	
	@RequestMapping("/login")
	public String login() {
		return "login";
	}
	
	@RequestMapping(value="/regist",method = RequestMethod.GET)
	public ModelAndView regist(ModelMap model){
		UserForm userForm = new UserForm();		  
		return new ModelAndView("regist").addObject(userForm);
	}
	
	@RequestMapping(value = "/register", method=RequestMethod.POST)
	@ResponseBody
	public String register(@ModelAttribute(value="userForm") UserForm userForm)
	{
		String result = this.uService.register(userForm);
		return result; 
	}
	
}
